package com.atstudy.set;

import java.util.HashSet;
import java.util.Iterator;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2023/1/3 13:37
 * @copyright: 博为峰
 */
public class HashSetDemo {
    public static void main(String[] args) {
        //不可重复，无序
        m1();
//        m2();
    }

    private static void m2() {
        HashSet hashSet = new HashSet();
        hashSet.add("a"); //add(Object e)
        hashSet.add("b");
        hashSet.add("a");

        Iterator iterator = hashSet.iterator();
        while (iterator.hasNext()){
            String str = (String) iterator.next();
            System.out.println(str);
        }
    }

    private static void m1() {
        HashSet hashSet = new HashSet();
        hashSet.add(new Student("张三", 20)); //add(Object e)
        hashSet.add(new Student("李四", 30));
        hashSet.add(new Student("张三", 20));

        Iterator iterator = hashSet.iterator();
        while (iterator.hasNext()){
            Student student = (Student) iterator.next();
            System.out.println(student.getName());
        }
    }
}
